package ciyuan.Block.Machine.yyj;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.inventory.container.FurnaceResultSlot;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;

/**
 * @author 150149
 */
public class YyjContainer extends Container {

    public ciyuan.Block.Machine.yyj.ContainerProgress containerProgress;
    public ciyuan.Block.Machine.yyj.YyjTileEntity YyjTileEntity=null;

    public YyjContainer(ContainerType<?> p_i50092_1_, int p_i50092_2_, PlayerInventory playerInventory, BlockPos blockPos, ContainerProgress containerProgress) {
        super(p_i50092_1_, p_i50092_2_);
        YyjTileEntity = (ciyuan.Block.Machine.yyj.YyjTileEntity) playerInventory.player.getCommandSenderWorld().getBlockEntity(blockPos);
        this.addSlot(new Slot(YyjTileEntity.getInventory(), 0, 25, 17));
        this.addSlot(new Slot(YyjTileEntity.getInventory(), 1, 25, 53));
        this.addSlot(new Slot(YyjTileEntity.getInventory(), 2, 55, 17));
        this.addSlot(new Slot(YyjTileEntity.getInventory(), 3, 55, 53));
        this.addSlot(new FurnaceResultSlot(playerInventory.player, YyjTileEntity.getInventory(), 4, 115, 35));
        layoutPlayerInventorySlots(playerInventory,8,84);
        this.containerProgress = containerProgress;
        this.addDataSlots(containerProgress);
    }

    @Override
    public boolean stillValid(PlayerEntity p_75145_1_) {
        return true;
    }

    private void layoutPlayerInventorySlots(IInventory inventory, int leftCol, int topRow) {
        // Player inventory
        addSlotBox(inventory, 9, leftCol, topRow, 9, 18, 3, 18);

        // Hotbar
        topRow += 58;
        addSlotRange(inventory, 0, leftCol, topRow, 9, 18);
    }

    private int addSlotBox(IInventory inventory, int index, int x, int y, int horAmount, int dx, int verAmount, int dy) {
        for (int j = 0; j < verAmount; j++) {
            index = addSlotRange(inventory, index, x, y, horAmount, dx);
            y += dy;
        }
        return index;
    }

    private int addSlotRange(IInventory inventory, int index, int x, int y, int amount, int dx) {
        for (int i = 0; i < amount; i++) {
            addSlot(new Slot(inventory, index, x, y));
            x += dx;
            index++;
        }
        return index;
    }

    @Override
    public ItemStack quickMoveStack(PlayerEntity p_82846_1_, int p_82846_2_) {
        return ItemStack.EMPTY;
    }

}
